package mygame.chameleonpoker;

import mygame.basicgameframework.Game;
import mygame.basicgameframework.Graphics;
import mygame.basicgameframework.Graphics.PixmapFormat;
import mygame.basicgameframework.Screen;

public class LoadingScreen extends Screen {

	private String number[] = {
			"A","2","3","4","5","6","7","8","9","10","J","Q","K"
	};
	
	
	public LoadingScreen(Game game) {
		super(game);
		Graphics g = game.getGraphics();
		
		/* -------------------- load the button's of the main menu -------------------------------*/
    	Assets.loading = g.newPixelmap("loading.png", PixmapFormat.RGB565);
		Assets.mainMenu = g.newPixelmap("mainmenu.png", PixmapFormat.ARGB4444);	
		Assets.buttonOnline = g.newPixelmap("buttononline.png", PixmapFormat.ARGB4444);
		Assets.buttonOnlineClick = g.newPixelmap("buttononlineclick.png", PixmapFormat.ARGB4444);
		Assets.buttonSingle = g.newPixelmap("buttonsingle.png", PixmapFormat.ARGB4444);
		Assets.buttonSingleClick = g.newPixelmap("buttonsingleclick.png", PixmapFormat.ARGB4444);
		Assets.buttonSettings = g.newPixelmap("buttonsettings.png", PixmapFormat.ARGB4444);
		Assets.buttonSettingsClick = g.newPixelmap("buttonsettingsclick.png", PixmapFormat.ARGB4444);
		Assets.buttonAbout = g.newPixelmap("buttonabout.png", PixmapFormat.ARGB4444);
		Assets.buttonAboutClick = g.newPixelmap("buttonaboutclick.png", PixmapFormat.ARGB4444);
		/* ----------------------------------------------------------------------------------------- */
		
		
		/* -------------------- load the assets in the game screen -------------------------------*/
		Assets.gamebackground = g.newPixelmap("gamebackground.png", PixmapFormat.ARGB4444);
		
		Assets.start = g.newPixelmap("start.png", PixmapFormat.ARGB4444);
		Assets.startClick = g.newPixelmap("startclick.png", PixmapFormat.ARGB4444);
		
		Assets.back = g.newPixelmap("back.png", PixmapFormat.ARGB4444);
		Assets.backClick = g.newPixelmap("backclick.png", PixmapFormat.ARGB4444);
		
		Assets.player = g.newPixelmap("player.png", PixmapFormat.ARGB4444);
		Assets.computer1 = g.newPixelmap("computer1.png", PixmapFormat.ARGB4444);
		Assets.computer2 = g.newPixelmap("computer2.png", PixmapFormat.ARGB4444);
		/* ----------------------------------------------------------------------------------------- */
		
		
		/* -------------------------------- load the poker cards -------------------------------  */
		for(int i = 0; i<13; i++) {
			Assets.spade[i] = g.newPixelmap("Spade/"+number[i]+".png", PixmapFormat.ARGB4444);
			Assets.heart[i] = g.newPixelmap("Heart/"+number[i]+".png", PixmapFormat.ARGB4444);
			Assets.club[i] = g.newPixelmap("Club/"+number[i]+".png", PixmapFormat.ARGB4444);
			Assets.diamond[i] = g.newPixelmap("Diamond/"+number[i]+".png", PixmapFormat.ARGB4444);
			
			Assets.number[i] = g.newPixelmap("Number/"+number[i]+".png", PixmapFormat.ARGB4444);		
		}
		Assets.joker[0] = g.newPixelmap("Joker/Joker2.png", PixmapFormat.ARGB4444);
		Assets.joker[1] = g.newPixelmap("Joker/Joker.png", PixmapFormat.ARGB4444);
		/* ---------------------------------------------------------------------------------------*/
		
		/* ------------------------ load the back pattern of the cards and the instruction -------------------------*/
		Assets.cardback = g.newPixelmap("cardback.png", PixmapFormat.ARGB4444);
	    Assets.cardburied = g.newPixelmap("burywords.png", PixmapFormat.ARGB4444);
	    Assets.carddealing = g.newPixelmap("dealingcard.png", PixmapFormat.ARGB4444);
	    
		for(int i=0; i<5; i++) {
			Assets.pattern[i] = g.newPixelmap("pattern" + String.valueOf(i) + ".png", PixmapFormat.ARGB4444);
		}
		/* -------------------------------------------------------------------------------------------------*/
		
		/* ------------------- load the lead&bury buttons -----------------------*/
		Assets.lead = g.newPixelmap("lead.png", PixmapFormat.ARGB4444);
		Assets.leadDisable = g.newPixelmap("leaddisable.png", PixmapFormat.ARGB4444);
		
		Assets.bury = g.newPixelmap("bury.png", PixmapFormat.ARGB4444);
		Assets.buryDisable = g.newPixelmap("burydisable.png", PixmapFormat.ARGB4444);
		
		Assets.penalty = g.newPixelmap("penalty.png", PixmapFormat.ARGB4444);
		Assets.result[0] = g.newPixelmap("resultwin.png", PixmapFormat.ARGB4444);
		Assets.result[1] = g.newPixelmap("resultlose.png", PixmapFormat.ARGB4444);
		
		Assets.menuMusic = game.getAudio().newMusic("menumusic.ogg");
		Assets.load = game.getAudio().newMusic("loadingmusic.ogg");
		Assets.gamescreen = game.getAudio().newMusic("gamescreen.ogg");
		
		Assets.leadCard = game.getAudio().newSound("leadcard.ogg");
		Assets.dealCard = game.getAudio().newSound("dealcard.ogg");
		Assets.touch = game.getAudio().newSound("touch.ogg");
		Assets.change = game.getAudio().newSound("change.ogg");
		Assets.select = game.getAudio().newSound("select.ogg");
		Assets.buryCard = game.getAudio().newSound("burycard.ogg");
		
		Assets.load.setLooping(false);
		Assets.load.play();
	}

	@Override
	public void update(float deltaTime) {
		// check if the loading screen has finished
		if(!Assets.load.isPlaying())
			game.setScreen(new MainMenuScreen(game));
	}

	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawPixelmap(Assets.loading, 0, 0);
	} 

	@Override
	public void pause() {
		Assets.load.pause();

	}

	@Override
	public void resume() {
		if(!Assets.load.isPlaying())
			Assets.load.play();
	}

	@Override
	public void dispose() {
		Assets.load.dispose();
	}

}
